
//
//  TopicView.m
//  7.13苏宁框架
//
//  Created by app01 on 15/7/17.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "TopicView.h"
#import "TopicModel.h"
#import "UIImage+CircleImage.h"
#import "Common.h"

@interface TopicView ()

{
    int i,j;
}
@property(weak,nonatomic)UIButton *btn1;
@property(weak,nonatomic)UIButton *btn2;
@property(weak,nonatomic)UIButton *btn3;
@end

@implementation TopicView





-(instancetype)init{
    
   
    if ([super init]) {
        self = [[NSBundle mainBundle]loadNibNamed:@"TopicVIew" owner:self options:nil][0];
        [self scale];
        [self addTimer];
        i = 0;
       
    }
    return self;
}

-(void)addTimer{
    
    NSTimer *timer  = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(scale) userInfo:nil repeats:YES];
    _timer = timer;
}

-(void)scale{
    
    for (UIButton *btn in _btn) {
        
        CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
        anim.keyPath = @"transform.scale";
        anim.values = @[@(1.1),@(1),@(1.1)];
        anim.duration = 3;
        anim.repeatCount = MAXFLOAT;
        [btn.layer addAnimation:anim forKey:nil];
        
        
        CAKeyframeAnimation *anim1 = [CAKeyframeAnimation animation];
        anim1.keyPath = @"transform.translation.y";
        anim1.values = @[@(-5),@(0),@(-5)];
        anim1.duration = 3;
        anim1.repeatCount = MAXFLOAT;
        [_upMove1.layer addAnimation:anim1 forKey:nil];
        [_upMove2.layer addAnimation:anim1 forKey:nil];
        
        CAKeyframeAnimation *anim2 = [CAKeyframeAnimation animation];
        anim2.keyPath = @"transform.translation.x";
        anim2.values = @[@(-5),@(0),@(-5)];
        anim2.duration = 3;
        anim2.repeatCount = MAXFLOAT;
        [_leftMove.layer addAnimation:anim2 forKey:nil];

        
    }
    
   
}

-(void)layoutSubviews{
    
    //_topicArray = [TopicModel modelArrayWithFilename:@"topicHeader.plist"];
    

    
    for (UIButton *btn in _btn) {
        TopicModel *model = _topicArray[i];
        UIImage *newImage = [UIImage circleImageWithName:model.image borderWidth:15 borderColor:[UIColor whiteColor]];
        [btn setBackgroundImage:newImage forState:UIControlStateNormal];
        [btn setBackgroundImage:newImage forState:UIControlStateHighlighted];
        if (i==0) {
            [_upMove1 setTitle:model.title forState:UIControlStateNormal];
        }else if(i==1){
            [_leftMove setTitle:model.title forState:UIControlStateNormal];
        }else{
            [_upMove2 setTitle:model.title forState:UIControlStateNormal];
        }
        
        
        i++;
        
    }
}



- (IBAction)tapAction:(id)sender {
    if ([self.delegate respondsToSelector:@selector(tapBtn:)]) {
        [self.delegate tapBtn:sender];
    }
}
@end
